<?php
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['OBJ'].'obj.mail.mex');


MYDCONN();
# CHECK FOR TASKS
$RunTasks = '';
$GetTasks = $GLOBALS['MYD']->db_array("SELECT stk_ID, stk_ProcessID, stk_ProcesstoUser, stk_PrcDateTime, stk_RegID, smb_CttEmail, srl_Name
				FROM sys_tasks
				INNER JOIN staff_members ON stk_ProcesstoUser = smb_ID
				INNER JOIN staff_rules ON stk_ProcessID = srl_PID AND stk_ProcesstoUser = srl_User
		WHERE stk_Flag = 2 AND (SUBDATE(stk_PrcDateTime, srl_Days) <= CURRENT_DATE || srl_Days = 0)");
for ($i=1;$i<=$GetTasks[0];$i++) {
	$PID = $GetTasks[$i]['stk_ProcessID'];
	include($GLOBALS['BIB'].'Pr_db/prc_modules/rh_dotasks.php');
	# Definicoes da comunicacao
	$PMAIL[390] = " O funcion�rio {$GetEdit[1]['smb_Name']} foi admitido e inicia fun��es em {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[391] = " Foi concluido o processo de admiss�o do funcion�rio {$GetEdit[1]['smb_Name']} e inicia fun��es em {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[392] = " O funcion�rio {$GetEdit[1]['smb_Name']} foi transferido e inicia fun��es em {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[393] = " O funcion�rio {$GetEdit[1]['smb_Name']} foi transferido e inicia fun��es em {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[394] = " O funcion�rio {$GetEdit[1]['smb_Name']} vai regrassar em {$GetTasks[$i]['stk_PrcDateTime']} � loja de {$GetEdit[1]['name']}";
	$PMAIL[395] = " O funcion�rio {$GetEdit[1]['smb_Name']} termina fun��es na data de {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[396] = " Concluido processo de demiss�o de {$GetEdit[1]['smb_Name']} a {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[397] = " O funcion�rio {$GetEdit[1]['smb_Name']} entra de ferias em {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[398] = " O funcion�rio {$GetEdit[1]['smb_Name']} entra de baixa em {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[399] = " Canceladas f�rias do funcion�rio {$GetEdit[1]['smb_Name']} a {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[401] = " Alteradas f�rias do funcion�rio {$GetEdit[1]['smb_Name']} a {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[402] = " Alterada baixa do funcion�rio {$GetEdit[1]['smb_Name']} a {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$PMAIL[403] = " Cancelada baixa do funcion�rio {$GetEdit[1]['smb_Name']} a {$GetTasks[$i]['stk_PrcDateTime']} na loja de {$GetEdit[1]['name']}";
	$RunTasks .= $GetTasks[$i]['stk_ID'].',';
	authmail('<no-reply@moneyexpress.pt>','ASD',$GetTasks[$i]['smb_CttEmail'],$GetTasks[$i]['srl_Name'],'','',$PMAIL[$GetTasks[$i]['stk_ProcessID']],'',$_sysconfMailString);
}
if ($RunTasks != '') {
	$GLOBALS['MYD']->db_query("UPDATE sys_tasks SET stk_Flag = 6 WHERE stk_ID IN (".(substr($RunTasks,0,strlen($RunTasks)-1)).")");
}